<template>
    <van-nav-bar left-arrow @click-left="onClickLeft" />
    <!-- 注销账号 -->
    <div
        style="text-align: center; position: fixed; bottom: 1.0667rem; left: 0; width: 100%; padding: 0px 15px; box-sizing: border-box;">
        <van-button type="danger" @click="removeFn">注销账号</van-button>
        <van-divider>温馨提示</van-divider>
        <p style="font-size: 15px; color: #666;">点击注销，账号就永久删除了！！</p>
    </div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { showConfirmDialog } from 'vant'
import { removeUserFunc, removePhotoFunc, getUserPicUrl } from '../api/index'
const $router = useRouter()
let img: any = ref('');
const onClickLeft = () => {
    $router.back();
}
const removeFn = () => {
    showConfirmDialog({
        title: '提示：',
        message: '确定删除账号吗？'
    })
        .then(
            async () => {
                // 确定
                await removeUserFunc()
                    .then(
                        content => {
                            // console.log('4.0', content)
                            if (content.code == 200) {
                                // 删除用户头像
                                removePhotoFunc({ picUrl: img.value })
                                .then(
                                    content=>{
                                        console.log('5.0',content)
                                    }
                                )
                                // 跳转登录选择的页面
                                $router.push({
                                    path: '/login_list'
                                })
                                localStorage.removeItem('auto_token');
                            }
                        }
                    )
            }
        )
        .catch(
            () => {
                // 取消
            }
        )
}


const initFn = async () => {
    // 获取用户头像
    await getUserPicUrl().then(
        content => {
            // console.log('1.0',content)
            if (content.code == 200) {
                // 设置头像
                img.value = content.user_url;
            }
        }
    )
}
initFn();

</script>
<style>
:root {
    --van-nav-bar-icon-color: #000;
    --van-dialog-confirm-button-text-color: #f00;
    /* --van-text-color: #f00; */
}

.van-button--danger {
    width: 100%;
}
</style>